package darknet;

import darknet.core.spec.friend.Friend;
import darknet.core.spec.net.Node;
import java.io.File;
import java.io.IOException;

/**
 * Some utilities for Darknet System.
 *
 * @author yoyo
 */
public class DarknetUtilities {

    /**
     * Export informations in a file.
     * 
     * Exported information are :
     * - pseudo
     * - certificate
     * - inet address
     * - port
     *
     * @param myNode Node informations of the current node.
     * @param myself Friend informations of the current node.
     * @param myInformationsFile The file to save informations.
     */
    public static void exportMyInformations(Node myNode, Friend myself,
            File myInformationsFile) throws IOException {

        if (myNode == null) {
            throw new IllegalArgumentException("myNode is null");
        }
        if (myself == null) {
            throw new IllegalArgumentException("myself is null");
        }
        if (myInformationsFile == null) {
            throw new IllegalArgumentException("myInformationsFile is null");
        }

        PublicInformation information = new PublicInformation(
                myself.getName(), myself.getCertificate(),
                myNode.getAddress(), myNode.getPort());
        
        information.save(myInformationsFile);
    }
}
